package array;

import java.util.Arrays;

/**
 * @Program: dataOJ->QueueArray
 * @Description:
 * @Author: Tansty
 * @Date: 2022-01-15 23:53
 * @Version： 1.0
 **/

public class QueueArray {
    // 头指针
    private int front;
    // 尾指针
    private int rear;
    private int maxSize;
    private int[] array;

    public QueueArray(int maxSize) {
        this.maxSize = maxSize;
        array = new int[maxSize];
        front = -1;
        rear = -1;
    }

    public Boolean isEmpty() {
        return this.front == this.rear;
    }

    public Boolean isFull() {
        return this.rear == maxSize - 1;
    }

    public void addQueue(int n) {
        if (isFull()) {
            throw new RuntimeException("队列已经满");
        }
        rear++;
        array[rear] = n;
    }

    public int getQueue() {
        if (isEmpty()) {
            throw new RuntimeException("队列为空");
        }
        front++;
        return array[front];
    }

    public void showQueue() {
        if (isEmpty()) {
            throw new RuntimeException("队列为空");
        }
        System.out.println(Arrays.toString(array));
    }

    public void showHead() {
        if (isEmpty()) {
            throw new RuntimeException("队列为空");
        }
        System.out.println(array[front + 1]);
    }

    public static void main(String[] args) {
        QueueArray queue = new QueueArray(5);
        queue.addQueue(5);
        queue.showHead();
        queue.showQueue();
        System.out.println(queue.getQueue());
        queue.showQueue();
    }

}
